export default{
    //获取从url中带过来的数据
    getParams:function(){

        var location = window.location;

        var hash = location.hash;

        var paramsFirst = hash.indexOf('?');

        var params = hash.substr(paramsFirst+1,hash.length);

        var once = params.split('&');

        var paramsObj = new Object();

        var tempKey = '';

        var tempValue = '';

        for( index in once ){

            tempKey =decodeURIComponent(once[index].split('=')[0]);

            tempValue = decodeURIComponent(once[index].split('=')[1]);

            paramsObj[tempKey] = tempValue;

        }

        return paramsObj;
    },
    //数据去重
    removalDup: function( arr ){
    
        var coachArray = arr.split(',');

        coachArray.pop();

        var temp = [];

        for(var i = 0; i < coachArray.length; i++){

            if(temp.indexOf(coachArray[i]) == -1){

                temp.push(coachArray[i]);

            }

        }
        
        var temp = temp.join(',');

        return temp;

    },
    //将二维数组转化成一维数组
    arrayObj:function( arr , param ){
                    
        var getObj=[];
        
        var arr2 = [];

        for( var i=0;i<arr.length;i++ ){

            if( arr[i].hasOwnProperty(param) ){
                
                getObj.push(arr[i][param]);

            }

        }

       var arr2 = [].concat.apply( [] , getObj );

       return arr2;

    },
    //连接字典表的公共接口
    comdictionaries: function( vals , reus){
                    
        var self = this;

        this.apipath( 'common/dictionaries?toggle=' + vals ).then(function( res ){
            
            var res = res.data;

            if(res.code != 200){

                self.layer.msg('获取失败！请检查网络');

            }
            
           return reus( res.response );

        });
    },
    //通过get的方式来连接
    comdictionPersonnel: function( vals , reus ){

        var self = this;

        this.apipath( vals ).then(function( res ){

            var res = res.data;
            
            if( res.code != 200 ){

                return self.layer.msg('获取失败,请检查网络');

            }

            return reus(res.response);

        });

    },
    //通过post链接工作方法
    horseroomconfig: function( path , data , resus ){

        var self = this;

        common.apiRequest( 
            {

                method: 'post',

                url: path,

                data: data

            }
        ).then(function( res ){

            var res = res.data;

            if( res.code != 200 ){

                return self.layer.msg(res.message);

            }

            return resus(res.response);

        });

    },
    //搜索公共函数
    multipleQuery: function( value ){

        var url = '&';

        var flag = false;

        for(var index in value){

            if( value[index] == '' || value[index] == undefined ){

                delete value[index];

                continue;

            }
            if( value[index] != '' && value[index] != undefined && index != '' ){

                if(flag == true){

                    url += '&'

                }

                url += index+'='+encodeURIComponent(value[index]);

            }

            flag = true;

        }

        return url;

    },

}